package mobi.yuanshen.controller;

import lombok.extern.slf4j.Slf4j;
import mobi.yuanshen.service.UploadService;
import mobi.yuanshen.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    UploadService uploadService;

    @PostMapping
    public Result upload(MultipartFile image) throws IOException {
        System.out.println("接收到文件" + image.getOriginalFilename());
        String url = uploadService.uploadFile (image);
        return Result.success(url);
    }
}
